package net.hekka.canyoutalk.fixture;



import java.sql.Connection;
import java.sql.SQLException;
import net.hekka.canyoutalk.data.constant.ConnectionConstant;
import net.hekka.canyoutalk.share.database.DatabaseConnector;

/**
 * JUnit Test에서 사용하게 될 테스트용 Object들을 생성하는 클래스.
 *
 * @author Jeffrey Ha
 * @since 1.0
 */
public class DatabaseTestFixture {

    public static Connection getConnection() throws SQLException, Exception {
        // ConnectionConstant에 지정한 databaseType 을 구한다.
        String databaseType = ConnectionConstant.databaseType;

        // Database 연결을 위한 기본 정보를 구한다.
        String databaseUrl = ConnectionConstant.getDatabaseUrl(databaseType);
        String databaseUser = ConnectionConstant.getDatabaseUser(databaseType);
        String databasePassword = ConnectionConstant.getDatabasePassword(databaseType);
        String databaseDriverName = ConnectionConstant.getDatabaseDriverName(databaseType);

        DatabaseConnector databaseConnector = new DatabaseConnector(databaseDriverName);
        databaseConnector.initConnector(databaseUrl, databaseUser, databasePassword);
        System.out.println("databaseUrl : " + databaseUrl);
        return databaseConnector.getDbConnection();
    }


}


